const Controllre = require("egg").Controller

class StudentController extends Controllre {
    async index() {
        let studentlist = await this.app.model.Student.findAll({
            include:{
                model:this.ctx.model.Clazz
            }
        })
        this.ctx.body = studentlist
    }
    async create() {
        let name = this.ctx.request.body.name;
        let achievement = this.ctx.request.body.achievement;
        let clazz_id = this.ctx.request.body.clazz_id;
        await this.app.model.Student.create({
            name: name,
            achievement: achievement,
            clazz_id: clazz_id
        })
        this.ctx.body = "添加成功"
    }
    async destroy() {
        let id = this.ctx.params.id;
        await this.app.model.Student.destroy({
            where:{
                id
            }
        })
        this.ctx.body = "删除成功"
    }
}

module.exports = StudentController